import java.util.Arrays;

public class Test {

    /*public static String myToString(int[] array){
        String str = "[";
        for (int i = 0; i < array.length; i++) {
            str += array[i];
            if(i != array.length - 1){
                str += ",";
            }
        }
        str += "]";
        return str;

    }

    public static void main(String[] args) {
        int[] array = {1,2,3,4,5};
        System.out.println(myToString(array));
    }*/

    //将原数组的值置为两倍
    /*public static int[] transform1(int[] array){
        int[] tmp = new int[3];
        for (int i = 0; i < array.length; i++) {
            tmp[i] = 2*array[i];
        }
        return tmp;
    }

    public static int[] transform2(int[] array){
        for (int i = 0; i < array.length; i++) {
            array[i] = 2 * array[i];
        }
        return array;
    }

    public static void main(String[] args) {
        int[] array = {1,2,3};
        transform1(array);
        System.out.println(Arrays.toString(array));

//        System.out.println(Arrays.toString(ret));
        transform2(array);
        System.out.println(Arrays.toString(array));

    }*/


    /*public static void main(String[] args) {
        int[] array = {1,2,3,4,5,6,7,8,9,10};
        int left = 0;
        int right = array.length - 1;
        System.out.println(Arrays.toString(array));

        while(left < right) {
            if(array[left] % 2 == 0){
                array[right] = array[left];
                left++;
                right--;
            }
            if(array[right] % 2 != 0){
                array[left] = array[right];
                left++;
                right--;
            }
        }
        System.out.println(Arrays.toString(array));
    }
*/


    //二分查找
    /*public static int buraySearch(int[] array, int key){
        int mid = (array.length - 1) / 2;
        int left = 0;
        int right = array.length - 1;

        while (left <= right){
            mid = (left+right)/2;
            if(key == array[mid]){
                return mid;
            }else if(array[mid] < key){
                left = mid + 1;
            }else{
                right = mid - 1;
            }
        }
        return -1;

    }

    public static void main(String[] args) {
        int[] array = {1,2,3,4,5,6,7,8,9,10};
        //int ret = buraySearch(array, 10);
        int ret = Arrays.binarySearch(array, 5);
        System.out.println(ret);
    }*/

    //冒泡排序
    public static void bulleySort(int[] array){
        for (int i = 0; i < array.length-1; i++) {
            boolean flag = false;
            for (int j = 0; j < array.length-1-i; j++) {
                if(array[j] > array[j+1]){
                    int tmp = array[j];
                    array[j] = array[j+1];
                    array[j+1] = tmp;
                    flag = true;
                }
            }
            if(flag == false){
                break;
            }
        }
    }

    public static void main(String[] args) {
        int[] array = {9,8,7,6,5,4,3,2,1,0};
        bulleySort(array);
        System.out.println(Arrays.toString(array));
    }




}
